package LC;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @ClassName LC531
 * @Description: TODO
 * @Author hl
 * @Date 2020/8/27
 * @Version V1.0
 **/
public class LC531 {
    public int findBottomLeftValue(TreeNode root) {
        ArrayList<ArrayList<Integer>> list=new ArrayList<>();
        Queue<TreeNode> queue=new LinkedList<>();
        queue.add(root);
        while(!queue.isEmpty()){
            int size=queue.size();
            ArrayList<Integer> slist=new ArrayList<>();
            for(int i=0;i<size;i++){
                TreeNode node=queue.poll();
                slist.add(node.val);
                if(node.left!=null){
                    queue.add(node.left);
                }
                if(node.right!=null){
                    queue.add(node.right);
                }
            }
            list.add(slist);
        }
        return  list.get(list.size()-1).get(0);
    }
}
